package com.cjb.cloudfabric.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;

/**
 * @Author chenjinbin
 * @Package IntelliJ IDEA
 * @Class ReadFileUtil
 * @Date 2023-10-07 下午11:23
 */
public class FileUtil {
    /**
     * 日志
     */
    private final static Logger log = LoggerFactory.getLogger(FileUtil.class);
    public static String readFile(String filePath) {
        try {
            File file = new File(filePath);
            FileInputStream fis = new FileInputStream(file);
            Scanner scanner = new Scanner(fis);
            StringBuilder sb = new StringBuilder();
            while (scanner.hasNextLine()) {
                sb.append(scanner.nextLine()).append("\n");
            }
            scanner.close();
            fis.close();
            return sb.toString();
        } catch (IOException e) {
            log.error("读取文件时发生错误：{}" , e.getMessage());
            return null;
        }
    }
}
